﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class ExportAssets : MonoBehaviour {

	[@MenuItem("ExportAssets/Build Asset Bundles")]
	static void BuildAssetBundles(){
		BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.StandaloneWindows);
	}

	[MenuItem("ExportAssets/AssetBundle LoadFile")]
	static void AssetBundleLoadFile()
    {
		AssetBundle assetBundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/cube");
		Material mat = (Material)assetBundle.LoadAsset("Red");
		Debug.Log(mat);
	}

	[MenuItem("ExportAssets/WWW AssetBundle")]
    static void WWWAssetBundle()
    {
		WWW data = new WWW("file://" + Application.streamingAssetsPath + "/cube");
		while (true) 
		{
            if (string.IsNullOrEmpty(data.error) || data.isDone)
            {

				break;
            }
		}
		Material mat = (Material)data.assetBundle.LoadAsset("Red");
		Debug.Log(mat);


	}

	[MenuItem("ExportAssets/WWW  LoadFromCacheOrDownload")]
	static void WWWLoadFromCacheOrDownload()
    {
		WWW data = WWW.LoadFromCacheOrDownload("file://" + Application.streamingAssetsPath + "/cube", new Hash128(1,1,1,1));
		while (true)
		{
			if (string.IsNullOrEmpty(data.error) || data.isDone)
			{

				break;
			}
		}
		Material mat = (Material)data.assetBundle.LoadAsset("Red");
		Debug.Log(mat);
	}
}
